/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-08-03
 * Time: 14:38
 */

//import java.io.*;

//public class Main {
//    public static void main(String[] args) throws IOException {
//        try (InputStream is = new FileInputStream("hello.txt")) {
//            while (true) {
//                int b = is.read();
//                if (b == -1) {
//                    // 代表⽂件已经全部读完
//                    break;
//                }
//
//                System.out.printf("%c", b);
//            }
//        }
//    }
//}
/*
public class Main {
    public static void main(String[] args) throws IOException {
        try (InputStream is = new FileInputStream("hello.txt")) {
            byte[] buf = new byte[1024];
            int len;

            while (true) {
                len = is.read(buf);
                if (len == -1) {
                    // 代表⽂件已经全部读完
                    break;
                }

                for (int i = 0; i < len; i++) {
                    System.out.printf("%c", buf[i]);
                }
            }
        }
    }
}*/

/*// 需要先在项⽬⽬录下准备好⼀个 hello.txt 的⽂件，⾥⾯填充 "你好中国" 的内容
public class Main {
    public static void main(String[] args) throws IOException {
        try (InputStream is = new FileInputStream("hello.txt")) {
            byte[] buf = new byte[1024];
            int len;
            while (true) {
                len = is.read(buf);
                if (len == -1) {
                    // 代表⽂件已经全部读完
                    break;
                }
                // 每次使⽤ 3 字节进⾏ utf-8 解码，得到中⽂字符
                // 利⽤ String 中的构造⽅法完成
                // 这个⽅法了解下即可，不是通⽤的解决办法
                for (int i = 0; i < len; i += 3) {
                    String s = new String(buf, i, 3, "UTF-8");
                    System.out.printf("%s", s);
                }
            }
        }
    }
}*/

//import java.io.*;
//import java.util.*;
//// 需要先在项⽬⽬录下准备好⼀个 hello.txt 的⽂件，⾥⾯填充 "你好中国" 的内容
//public class Main {
//    public static void main(String[] args) throws IOException {
//        try (InputStream is = new FileInputStream("hello.txt")) {
//            try (Scanner scanner = new Scanner(is, "UTF-8")) {
//                while (scanner.hasNext()) {
//                    String s = scanner.next();
//                    System.out.print(s);
//                }
//            }
//        }
//    }
//}
//import java.io.*;
//public class Main {
//    public static void main(String[] args) throws IOException {
//        try (OutputStream os = new FileOutputStream("output.txt")) {
//            os.write('H');
//            os.write('e');
//            os.write('l');
//            os.write('l');
//            os.write('o');
//            // 不要忘记 flush
//            os.flush();
//        }
//    }
//}
//import java.io.*;
//public class Main {
//    public static void main(String[] args) throws IOException {
//        try (OutputStream os = new FileOutputStream("output.txt")) {
//            byte[] b = new byte[] {
//                    (byte)'G', (byte)'o', (byte)'o', (byte)'d'
//            };
//            os.write(b);
//
//            // 不要忘记 flush
//            os.flush();
//        }
//    }
//}
/*import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("output.txt")) {
            byte[] b = new byte[] {
                    (byte)'G', (byte)'o', (byte)'o', (byte)'d', (byte)'B', (byte)'a'
            };
            os.write(b, 0, 4);

            // 不要忘记 flush
            os.flush();
        }
    }
}*/

/*import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("output.txt")) {
            String s = "你好中国";
            byte[] b = s.getBytes("utf-8");
            os.write(b);

            // 不要忘记 flush
            os.flush();
        }
    }
}*/

/*OutputStream os = ...;
        OutputStreamWriter osWriter = new OutputStreamWriter(os, "utf-8"); // 告诉
        PrintWriter writer = new PrintWriter(osWriter);
// 接下来我们就可以⽅便的使⽤ writer 提供的各种⽅法了
        writer.print("Hello");
        writer.println("你好");
        writer.printf("%d: %s\n", 1, "没什么");
// 不要忘记 flush
        writer.flush();*/
//import java.io.*;
//public class Main {
//    public static void main(String[] args) throws IOException {
//        try (OutputStream os = new FileOutputStream("output.txt")) {
//            try (OutputStreamWriter osWriter = new OutputStreamWriter(os, "UTF-8
// try (PrintWriter writer = new PrintWriter(osWriter)) {
//                writer.println("我是第⼀⾏");
//                writer.print("我的第⼆⾏\r\n");
//                writer.printf("%d: 我的第三⾏\r\n", 1 + 1);
//                writer.flush();
//            }
//        }
//    }
//}


